package src.edu.wayne.cs.csc4110.hw6.implementations;

import java.util.HashSet;

import javax.swing.JPanel;

import src.edu.wayne.cs.csc4110.hw6.implementations.dbase.FacelookDatabaseImpl;
import src.edu.wayne.cs.csc4110.hw6.implementations.stateMachine.StateMachine;
import src.edu.wayne.cs.csc4110.hw6.interfaces.FacelookDatabase;
import src.edu.wayne.cs.csc4110.hw6.interfaces.Game;
import src.edu.wayne.cs.csc4110.hw6.interfaces.GameStatus;
import src.edu.wayne.cs.csc4110.hw6.interfaces.FrameWork;
import src.edu.wayne.cs.csc4110.hw6.interfaces.State;
import src.edu.wayne.cs.csc4110.hw6.interfaces.User;
import src.edu.wayne.cs.csc4110.hw6.plugins.GamePlugin;

public class FrameWorkImpl implements FrameWork {

	private static FrameWork frameWork; 
	private static State stateMachine;
	
	private HashSet<User> usersInSession;
	private FacelookDatabase dataBase;
	private Game plugin;
	
	
	public synchronized static FrameWork getFrameWork() {
		if (frameWork == null)
		{
			frameWork = new FrameWorkImpl();
			
		}
		return frameWork;
	}
	
	private FrameWorkImpl()	{
		this.setDataBase(new FacelookDatabaseImpl());
		setUsersInSession(new HashSet<User>());
		stateMachine = new StateMachine(this);	
	}
	
	@Override
	public FacelookDatabase getDataBase() {
		return dataBase;
	}

	public void setDataBase(FacelookDatabase dataBase) {
		this.dataBase = dataBase;
	}

	@Override
	public boolean startFrameWork(GamePlugin plugin) {
		this.plugin = plugin;
		return true;
	}

	@Override
	public void setScreen(JPanel gamePanel, GameStatus gameStatus,
			int userId) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean saveGame(int gameId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean quitGame(int gameId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int startGame(int userId) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Game getPlugin() {
		return plugin;
	}

	@Override
	public void setPlugin(Game plugin) {
		this.plugin = plugin;
	}

	@Override
	public void startUserSession() {
		stateMachine.goToLoggedInState();
	}
	
	@Override
	public void addUserToSession(User user){
		usersInSession.add(user);
	}

	@Override
	public HashSet<User> getUsersInSession() {
		return usersInSession;
	}

	@Override
	public void setUsersInSession(HashSet<User> usersInSession) {
		this.usersInSession = usersInSession;
	}

}
